/**
*  合并二叉树， 将二叉树的左右两棵树， 各自相加
*/

let tree1 = {
    node:1,
    left:{
        node:2,
        left:{
            node:3,
            left:null,
            right:null
        }
    },
    right: {
        node:4,
        left:{
            node:5,
            left:{
                node:6,
                left:null,
                right:null
            },
            right:null
        },
        right:null
    }
}
let tree2 = {
    node:1,
    left:{
        node:2,
        left:{
            node:3
        }
    },
    right: {
        node:4,
        left:{
            node:5,
            left:{
                node:6
            },
            right:null
        },
        right:null
    }
}

function mergeTrees(leftTree, rightTree){
    // 两棵树都没有
    if(!leftTree && !rightTree) return null;

    // 一棵树没有
    if(!leftTree) return  rightTree
    if(!rightTree) return  leftTree


    // 两个树都有
    if(leftTree && rightTree){
        leftTree.node  += rightTree.node
        leftTree.left = mergeTrees(leftTree.left, rightTree.left)
        rightTree.right = mergeTrees(leftTree.right, rightTree.right)
    }

    return leftTree
}

console.log(mergeTrees(tree1, tree2));
